import pagination from '@/views/pagination'  //分页组件
import {confirm} from '@/utils/confirm'      //二次确认组件
import agentHttp from '@/utils/agentHttp'    //请求方法
import dialogForm from './edit'
export default {
  name: 'messageFlow',
  components:{dialogForm,pagination},
  created(){
     this.seachData1()
  },
  data() {
  	return {
      //表格字段
      tableData: [],
      workflowStatus:"",
        //分页数据
         //弹窗状态数据
      dialogSendData:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      searchForm:{},
      parent:true,

      formLabelWidth:"120px",
      //表格字段
      tableData1: [],
      rules1: {status: [{ required: true, message: '请选择流程名称', trigger: 'change' ,type:"number"}]},
      dialogSendData1:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      dialogForm1:{
        status:""
      },
      statusMap:""
        
  	}
  },
  methods: {
    seachData1(){
      agentHttp.get('adminApi/admin/workflow_subject/get_list').then((data)=>{
        this.tableData1 = data.data.list;
        this.statusMap=data.data.statusMap;
      })
    },
    //修改
    handleEdit1(index, row){
      debugger
      //row?this.dialogSendData1.row= row :this.dialogSendData1.row="";
      row?this.dialogForm1.status=row.status:this.dialogForm1.status="";
      row?this.dialogForm1.id=row.id:this.dialogForm1.id="";
      row?this.dialogForm1.workflowSubjectName=row.workflowSubjectName:this.dialogForm1.workflowSubjectName="";
      this.dialogSendData1.isAdd=true;
      this.dialogSendData1.dialogFormVisible=true;
    },
    //编辑
    handlePush1(index, row){
      this.parent=false;
      this.dialogSendData.id=row.id;
      this.dialogSendData.status=row.status;
      this.dialogSendData.workflowSubjectName=row.workflowSubjectName;
      //this.dialogSendData.row="";
      this.seachData();
    },
    retrunParentList1(){
      this.dialogSendData1.dialogFormVisible=false;
    },
    submitParent1(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(this.dialogSendData1.id===""){
              //添加
              this.addData1();
            }else{
              //修改
              this.editData1();
            }
          }else{
            this.$nextTick(()=>{
              this.$message.warning(document.getElementsByClassName('el-form-item__error')[0].innerText||"提交失败");
              return false;
            })
          }
      });
    },
    addData1(){
      agentHttp.postJson('adminApi/admin/workflow_subject/add',this.dialogForm1).then((data)=>{
          if(data.success){ 
            this.seachData1(); 
            this.$message.success(data.data||"添加成功");
            setTimeout(()=>{
              this.dialogSendData1.dialogFormVisible=false;
            },500)
          } 
      }) 
    },
    editData1(){
      agentHttp.putJson('adminApi/admin/workflow_subject/update',this.dialogForm1).then((data)=>{
          if(data.success){ 
            this.seachData1(); 
            this.$message.success(data.data||"修改成功");
            setTimeout(()=>{
              this.dialogSendData1.dialogFormVisible=false;
            },500)
          } 
      }) 
    },

    retrunParentList(){
      this.parent=true;
    },
    seachData(){
      agentHttp.get('adminApi/admin/work_flow_template/get_list/'+this.dialogSendData.status ).then((data)=>{
        this.tableData = data.data.list;
        this.workflowStatus=data.data.workflowStatus;
      })
    },
    /*表格操作按钮*/
    //删除
    handleDel(index, row){
        confirm(()=>{
          agentHttp.del('adminApi/admin/work_flow_template/delete/'+row.id).then((data)=>{
            if(data.success){  
                this.$message.success(data.data||"删除成功");
                this.seachData();
                //这里编写数据赋值或者其他逻辑  例如：this.tableData = data;
            } 
          })
        },()=>{
           this.$message.info('已取消删除'); 
        },"确认删除该条数据吗?")
    },
    handleMove(index, row){
      agentHttp.put('adminApi/admin/work_flow_template/exchange_sort_number/'+row.sortNumber).then((data)=>{
        if(data.success){  
            this.seachData();
        } 
      })
    },
    //修改
    handleEdit(index, row){
      row?this.dialogSendData.row= row :this.dialogSendData.row="";
      row?this.dialogSendData.workflowNodeTerm= row.workflowNodeTerm :this.dialogSendData.workflowNodeTerm="";
      this.dialogSendData.isAdd=true;
      this.dialogSendData.dialogFormVisible=true;
    }
  }
}